<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="../../attr.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="${ctx}/css/bootstrap.min.css" type="text/css">
    <style>
        [v-cloak] {
            display: none !important;
        }
        @page  {
            size: a4 landscape;
        }
        @media print {
            .see{
                display: none;
            }
            table tr td{
                border: 1px solid #0C1A35 !important;
                padding:0 0 0 0 !important;
                font-size:1px !important;
            }
            table tr th{
                border: 1px solid #0C1A35 !important;
                padding:0 0 0 0 !important;
                font-size:1px !important;
            }
        }
    </style>
</head>
<body>
<div id="app" v-cloak>
    <h3 style="text-align: center"><b>手术通知</b></h3>
    <div><input type="date" v-model="time" style="border: none" min="2000-01-01" max="9999-12-31"><button onclick="print()" class="see btn btn-primary" style="margin-left: 20px">打印</button></div>
    <br>
    <div>
        <table class="table table-bordered " cellpadding="0">
            <thead>
            <tr>
                <th>手术室</th>
                <th>时间</th>
                <th class="see">首台开台时间</th>
                <th>患者</th>
                <th>性别</th>
                <th>年龄</th>
                <th>床号</th>
                <th>住院号</th>
                <th style="width: 6%">医师嘱托</th>
                <th>诊断</th>
                <th style="width: 15%">手术方式</th>
                <th>主刀</th>
                <th>一助</th>
                <th>二助</th>
                <th>三助</th>
                <th style="width: 5%">麻醉方式</th>
                <th>主麻</th>
                <th>辅麻</th>
                <th>上级医师</th>
                <th>器械</th>
                <th>巡回</th>
                <th>洗手</th>
                <th>等级</th>
                <th style="width: 7%">科室</th>
            </tr>
            </thead>
            <tbody>
            <tr v-for="(array , index) in arrays" :key="array.id">
                <td></td>
                <td>{{setTime(array.operationApplyDatetime)}}</td>
                <td class="see"></td>
                <td>{{array.patientName}}</td>
                <td>{{array.patientSex}}</td>
                <td>{{array.patientAge}}</td>
                <td>{{array.bedNo}}</td>
                <td>{{array.hosId}}</td>
                <td>{{array.operationRemark}}</td>
                <td>{{array.operationDiagnosis}}</td>
                <td>{{array.operationTemplateName}}</td>
                <td>{{array.operationDoc}}</td>
                <td colspan="3">{{array.operationAssistant}}</td>
                <td>{{array.anesthesiaScheme}}</td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td>{{array.operationRank}}</td>
                <td>{{array.detpName}}</td>
            </tr>
            <tr v-for="(flow , index) in flows" :key="flow.id">
                <td>{{flow.operationRoomId}}-{{flow.operationRoomOrder}}</td>
                <td>{{setTime(flow.operationEfftime)}}</td>
                <template>
                    <td v-if="flow.operationRoomOrder==1" class="see">{{getFirstDoTime(flow.operationRoomId)}}</td>
                    <td v-else class="see"></td>
                </template>
                <td>{{flow.patientName}}</td>
                <td>{{flow.patientSex}}</td>
                <td>{{flow.patientAge}}</td>
                <td>{{flow.bedNo}}</td>
                <td>{{flow.hosId}}</td>
                <td>{{flow.operationMark}}</td>
                <td><!--{{flow.operationDiagnosis}}--></td>
                <td>{{flow.operationName}}</td>
                <td>{{flow.operationDoc}}</td>
                <td>{{getDocAids(flow.operationDocAide,1)}}</td>
                <td>{{getDocAids(flow.operationDocAide,2)}}</td>
                <td>{{getDocAids(flow.operationDocAide,3)}}</td>
                <td>{{flow.operationAnaesthesia}}</td>
                <td>{{flow.operationCrnaName}}</td>
                <td>{{flow.operationMzDoc}}</td>
                <td>{{flow.operationMzLeader}}</td>
                <td>
                    <font v-if="flow.attend">{{setAttend(flow.attend,'tool')}}</font>
                    <font v-else></font>
                </td>
                <td>
                    <font v-if="flow.attend">{{setAttend(flow.attend,'tour')}}</font>
                    <font v-else></font>
                </td>
                <td>
                    <font v-if="flow.attend">{{flow.attend.operationWash}}</font>
                    <font v-else></font>
                </td>
                <td>{{flow.operationRank}}</td>
                <td>{{flow.detpName}}</td>
            </tr>
            </tbody>
        </table>
    </div>
</div>
</body>
<script type="text/javascript" src="/js/vue.min.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery.js"></script>
</html>
<script>
    var app = new Vue({
        el: "#app",
        data: {
            time: '',
            minTime: '',
            flows: [],
            arrays:[],
            roomArranges:[],
        },
        watch: {
            'time': function (val, old) {
                if (old == null || old.trim() == '' || val==null || val.trim()=='') {
                    return;
                }
                this.findFlows(val + " 00:00:00");
                this.findArrays(val);
            },
        },
        created: function () {
            this.findRoonArranges();
            this.minTime = this.getTimeShort(0);
            this.time = this.getTimeShort(1);
            this.findFlows(this.getTime(1));
            this.findArrays(this.getTimeShort(1));
        },
        methods: {
            findFlows: function (dateStr) {
                var that = this;
                $.post('http://172.20.90.3:8080/package/findByEfftime', {operationEfftime: dateStr}, function (data) {
                    if (data.success) {
                        if (data.data != null) {
                            that.flows = data.data;
                        }
                    }
                })
            },
            findArrays:function(time){
                var that=this;
                $.post('http://172.20.90.3:8080/package/findByTime',{time:time},function(data){
                    if(data.success){
                        if(data.data!=null){
                            that.arrays=data.data;
                        }
                    }
                })
            },
            setTime:function(date){
                return date.substring(11,16);
            },
            getTimeShort: function (add) {
                var date = new Date();
                var yyyy = date.getFullYear();
                var MM = date.getMonth() + 1;
                var dd = date.getDate() + add;
                switch (MM) {
                    case 1:
                        if (dd > 31) {
                            dd = dd - 31;
                            MM = MM + 1;
                        }
                        break;
                    case 2:
                        if ((yyyy % 100 == 0 && yyyy % 400 == 0) || (yyyy % 100 != 0 && yyyy % 4 == 0)) {
                            if (dd > 29) {
                                dd = dd - 29;
                                MM = MM + 1;
                            }
                        } else {
                            if (dd > 28) {
                                dd = dd - 28;
                                MM = MM + 1;
                            }
                        }
                        break;
                    case 3:
                        if (dd > 31) {
                            dd = dd - 31;
                            MM = MM + 1;
                        }
                        break;
                    case 4:
                        if (dd > 30) {
                            dd = dd - 30;
                            MM = MM + 1;
                        }
                        break;
                    case 5:
                        if (dd > 31) {
                            dd = dd - 31;
                            MM = MM + 1;
                        }
                        break;
                    case 6:
                        if (dd > 30) {
                            dd = dd - 30;
                            MM = MM + 1;
                        }
                        break;
                    case 7:
                        if (dd > 31) {
                            dd = dd - 31;
                            MM = MM + 1;
                        }
                        break;
                    case 8:
                        if (dd > 31) {
                            dd = dd - 31;
                            MM = MM + 1;
                        }
                        break;
                    case 9:
                        if (dd > 30) {
                            dd = dd - 30;
                            MM = MM + 1;
                        }
                        break;
                    case 10:
                        if (dd > 31) {
                            dd = dd - 31;
                            MM = MM + 1;
                        }
                        break;
                    case 11:
                        if (dd > 30) {
                            dd = dd - 30;
                            MM = MM + 1;
                        }
                        break;
                    case 12:
                        if (dd > 31) {
                            dd = dd - 31;
                            MM = 1;
                            yyyy = yyyy + 1;
                        }
                        break;

                }
                return yyyy + "-" + (MM < 10 ? ("0" + MM) : MM) + "-" + (dd < 10 ? ("0" + dd) : dd);
            },
            getTime: function (add) {
                return this.getTimeShort(add) + " 00:00:00";
            },
            findRoonArranges:function(){
                var that=this;
                $.post('http://172.20.90.3:8080/package/findAll',function(data){
                    if(data.success){
                        that.roomArranges=data.data;
                    }
                })
            },
            getRoomArrange:function(roomId){
                var that=this;
                var target=that.roomArranges;
                for(var i=0;i<target.length;i++){
                    if(target[i].roomsetId==roomId){
                        return target[i];
                    }
                }
                return null;
            },
            getFirstDoTime:function(roomId){
                var that=this;
                var target=that.getRoomArrange(roomId);
                return target==null?null:target.firstDoTime==null?null:target.firstDoTime.substring(11,16);
            },
            getDocAids: function (names, i) {
                if(names==null){
                    return '';
                }
                var array = names.split(",");
                var len = array.length;
                return len > i - 1 ? array[i - 1] : '';
            },
            setAttend: function (attend, type) {
                var target = "";
                if (type == 'tour') {
                    target=(attend.operationTourOne == null ? "" : ( attend.operationTourOne)) +
                        (attend.operationTourTwo == null ? "" : ("," + attend.operationTourTwo));
                } else if (type == 'tool') {
                    target=(attend.operationToolOne == null ? "" : (attend.operationToolOne)) +
                        (attend.operationToolTwo == null ? "" : ("," + attend.operationToolTwo));
                }
                return target;
            },
        },
    })
</script>